<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算属性与侦听器</title>
    <script src="./vue.js"></script>
</head>
<body>
<div id="root">
    姓：<input v-model="firstName"/>
    名：<input v-model="lastName"/>
    <div>{{fullName}}</div>
    <div>{{count}}</div>
</div>
<script>
    new Vue({
        el: "#root",
        data: {
            firstName: '',
            lastName: '',
            count: 0
        },
        //计算属性
        computed: {
            fullName: function () {
                return this.firstName + ' ' + this.lastName
            }
        },
        //侦听器：监听某个数据，当数据发生改变时，执行具体业务逻辑
        watch: {
            firstName: function () {
                this.count++
            },
            lastName: function () {
                this.count++
            }
        }
    })
</script>
</body>
</html>